﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Azure.Online.Proxy.Server {
    public class NameValueDictionary : IDictionary<string, string> {

        private class Header {
            public string Name;
            public string NameLowered;
            public string Value;
        }

        private readonly Dictionary<string, Header> _inner = new Dictionary<string, Header>();

        public IEnumerator<KeyValuePair<string, string>> GetEnumerator() {
            throw new NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }

        public void Add(KeyValuePair<string, string> item) {
            throw new NotImplementedException();
        }

        public void Clear() {
            _inner.Clear();
        }

        public bool Contains(KeyValuePair<string, string> item) {
            throw new NotImplementedException();
        }

        public void CopyTo(KeyValuePair<string, string>[] array, int arrayIndex) {
            throw new NotImplementedException();
        }

        public bool Remove(KeyValuePair<string, string> item) {
            throw new NotImplementedException();
        }

        public int Count { get; private set; }
        public bool IsReadOnly { get; private set; }
        public bool ContainsKey(string key) {
            throw new NotImplementedException();
        }

        public void Add(string key, string value) {
            throw new NotImplementedException();
        }

        public bool Remove(string key) {
            throw new NotImplementedException();
        }

        public bool TryGetValue(string key, out string value) {
            throw new NotImplementedException();
        }

        public string this[string key] {
            get {
                key = key.ToLowerInvariant();
                Header header;
                if (_inner.TryGetValue(key, out header)) return header.Value;
                return null;
            }
            set {
                _inner[key.ToLowerInvariant()] = new Header {
                    Name = key,
                    NameLowered = key.ToLowerInvariant(),
                    Value = value
                };
            }
        }

        public ICollection<string> Keys {
            get {
                return _inner.Select(kv => kv.Value.Name).ToList();
            }
        }

        public ICollection<string> Values { get; private set; }
    }
}
